from flask_sqlalchemy import SQLAlchemy
from datetime import datetime



db = SQLAlchemy()


class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    details = db.Column(db.String(128))
    timestamp = db.Column(db.DateTime, default=datetime.now, index=True)    

    def to_json(self):
        return {
            "id": self.id,
            "message": self.details,
            "timestamp": self.timestamp
        }